﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace eBirdAttend
{
    public partial class SelectPort : Form
    {
        UserControl _UserControls;
        EnrollToeOffice _eOfficeSettings;
        EnrollToBioFinger _biofingerSettings;
        string _devName;
        string _devID;
        string _employID;

        public string EmployID
        {
            get { return _employID; }
            set { _employID = value; }
        }
        DataSet ds;
        public SelectPort()
        {
            InitializeComponent();
        }

        private void SelectPort_Load(object sender, EventArgs e)
        {
            InstDevLoad();
        }

        private void InstDevLoad()
        {
            try
            {
                XmlDocument _settingsFile = new XmlDocument();
                _settingsFile.Load("config.xml");
                XmlNode _rootNode = _settingsFile.DocumentElement;
                XmlNodeList _imageList = _rootNode.SelectNodes("/eOffice/InstalledDevices/device");
                
                ds = new DataSet();
                ds.Tables.Add();
                ds.Tables[0].Columns.Add("Name");
                ds.Tables[0].Columns.Add("Id");
                ds.Tables[0].Rows.Add("Select Device", null);
                for (int i = 0; i < _imageList.Count; ++i)
                {
                    if (_imageList[i].Attributes["Name"] == null) continue;
                    _devName = _imageList[i].Attributes["Name"].Value;
                    _devID = _imageList[i].Attributes["ID"].Value;
                    //comboBox1.Items.Add(_devName.ToString());
                    ds.Tables[0].Rows.Add(_devName, _devID);
                   
                }
                comboBox1.DataSource = ds.Tables[0].DefaultView;
                comboBox1.DisplayMember = ds.Tables[0].Columns[0].ColumnName;
                comboBox1.ValueMember = ds.Tables[0].Columns[1].ColumnName;
                comboBox1.SelectedIndex = 0;
            }
            catch (Exception e)
            {
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int _cmbIndex;
            _cmbIndex = Convert.ToInt32(comboBox1.SelectedIndex.ToString());
            switch (_cmbIndex)
            {
                case 0:
                    {
                        if (_UserControls != null)
                        {
                            _UserControls.Dispose();
                        }
                        groupBox1.Visible = false;
                        return;
                        break;
                    }
                case 1:
                    {
                        groupBox1.Visible = true;
                        if (_UserControls != null)
                        {
                            _UserControls.Dispose();
                        }
                        _biofingerSettings = new EnrollToBioFinger();
                        _biofingerSettings.Location = new System.Drawing.Point(10, 15);
                        _biofingerSettings.Name = "BioFingerConfigure";
                        //_biofingerSettings.Size = new System.Drawing.Size(400, 200);
                        _biofingerSettings.TabIndex = 1;
                        _biofingerSettings.EmpID = _employID.ToString();
                        _biofingerSettings.DeviceName = comboBox1.Text.ToString();
                        _biofingerSettings.DeviceID = comboBox1.SelectedValue.ToString();
                        groupBox1.Controls.Add(_biofingerSettings);
                        _biofingerSettings.Visible = true;
                        _biofingerSettings.BringToFront();
                        this.Text = "BioFinger --- Configure";
                        _UserControls = (UserControl)_biofingerSettings;
                        break;
                    }
                case 2:
                    {
                        groupBox1.Visible = true;
                        if (_UserControls != null)
                        {
                            _UserControls.Dispose();
                        }
                        _eOfficeSettings = new EnrollToeOffice();
                        _eOfficeSettings.Location = new System.Drawing.Point(10, 15);
                        _eOfficeSettings.Name = "eOfficeConfigure";
                        //_eOfficeSettings.Size = new System.Drawing.Size(400, 200);
                        _eOfficeSettings.TabIndex = 1;
                        groupBox1.Controls.Add(_eOfficeSettings);
                        _eOfficeSettings.Visible = true;
                        _eOfficeSettings.BringToFront();
                        this.Text = "eOffice --- Configure";
                        _UserControls = (UserControl)_eOfficeSettings;
                        break;
                    }

            }

        }
    }
}
